var app = getApp(),
  that;
Page({
  data: {
    wdzd: [],
    tabs: ["钱包明细", "支付账单"],
    activeIndex: 0,
    banertext: "钱包明细",
    bdtext: "可用余额(元)",
    issx: !1,
    moneyDetail: [],
    limit: 10,
    page: 1,
    memberId: {},
    walletDetails: [],
    payBills:[],
    toPayBills:[],
    rows:10,
    jzgd: !0,
    mygd: !1,
    blane:''
  },
  tabClick: function(t) {
    console.log(t.currentTarget.id)
    this.setData({
      activeIndex: t.currentTarget.id
    }), 0 == t.currentTarget.id && this.setData({
      banertext: "钱包明细"
    }), 1 == t.currentTarget.id && this.setData({
      banertext: "支付账单"
    });
  },
  onLoad: function(t) {
    console.log(t.payId)
    that = this
    that.setData({
      activeIndex: (t.payId==1  ? t.payId : 0)
    });
  },
  onShow: function() {
    that.setData({
      memberId: wx.getStorageSync('bizUserInfo').id,
      blane: wx.getStorageSync('bizUserInfo').balance
    });
    that = this;
    //钱包明细
    this.walletDetails();
    // 我的账单
    this.payBills();
    var e = wx.getStorageSync("bizUserInfo");
    console.log(e)
    e ? this.setData({
      bizUserInfo: e
    }) : this.setData({
      bizUserInfo: this.data.bizUserInfo
    });
  },
  //钱包明细
  walletDetails() {
    app.getData({
      url: app.api.getMoneyDetail(),
      method: 'POST',
      data: {
        customId: that.data.memberId,
        limit: 10,
        page: that.data.page
      },
      ok: function(res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            if (that.data.moneyDetail.length == res.data.totals) {
              that.setData({
                jzgd: !1,
                mygd: !0
              })
            } else {
              res.data.totals == null || res.data.list == "" || res.data.list.length < 1 ? that.setData({
                mygd: !0,
                jzgd: !1
              }) :
                res.data.list.length < 10 ? that.setData({
                  jzgd: !1,
                  mygd: !0,
                  moneyDetail: that.data.moneyDetail.concat(res.data.list)
                }) :
                  that.setData({
                    jzgd: !0,
                    page: that.data.page + 1,
                    moneyDetail: that.data.moneyDetail.concat(res.data.list)
                  });
            }
          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }

    });
  },
  onReachBottom: function () {
    console.log("上拉加载", this.data.pagenum);
    !this.data.mygd && this.data.jzgd && (this.setData({
      jzgd: !1
    }), this.walletDetails(), this.payBills());
  },
  //支付账单
  payBills() {
    app.getData({
      url: app.api.getPayBills(that.data.memberId,that.data.page,10),
      method: 'GET',
      ok: function (res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {

            if (that.data.toPayBills.length == res.data.totals) {
              that.setData({
                jzgd: !1,
                mygd: !0
              })
            } else {
              res.data.totals == null || res.data.list == "" || res.data.list.length < 1 ? that.setData({
                mygd: !0,
                jzgd: !1
              }) :
                res.data.list.length < 10 ? that.setData({
                  jzgd: !1,
                  mygd: !0,
                  toPayBills: that.data.toPayBills.concat(res.data.list)
                }) :
                  that.setData({
                    jzgd: !0,
                    page: that.data.page + 1,
                    toPayBills: that.data.toPayBills.concat(res.data.list)
                  });
            }





            // that.setData({
            //   toPayBills: res.data.list
            // })
          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }
    });
  }
});